﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;


using Urgencias.Modelo;

namespace Urgencias.Controlador
{
    class Conexion
    {
        private static Conexion instance;
        private SqlConnection con;

        public SqlConnection Con
        {
            get
            {
                con=new SqlConnection(connectionString);
                con.Open();
                return con; }
            set { con = value; }
        }
        public static string connectionString = "Data Source=(LocalDB)\\v11.0;AttachDbFileName=|DataDirectory|\\Database.mdf;Connect Timeout=30";

        private Conexion()
        {
            con = new SqlConnection(connectionString);
        }

        public static Conexion Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new Conexion();
                }
                else
                    instance.con = new SqlConnection(connectionString);
                return instance;
            }
        }
        #region ingreso

        public bool conectar(String username, String password)
        {
            try
            {
                SqlConnection con = new SqlConnection(connectionString);
                SqlCommand com = new SqlCommand();
                con.Open();

                com.CommandText = "select * from Usuario where Username='" + username + "' and Pass='" + password + "'";
                com.Connection = con;

                SqlDataReader ejecuta = com.ExecuteReader();

                if (ejecuta.Read() == true)
                {
                    con.Close();
                    return true;
                }
                else
                {
                    con.Close();
                    return false;
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                con.Close();
                throw;
            }
        }

       


       #region eliminar

       public void eliminarPaciente(string rut)
       {
           SqlConnection con = new SqlConnection(connectionString);
           SqlCommand com = new SqlCommand();
           con.Open();
           com = new SqlCommand("DELETE FROM paciente WHERE rut = '" + rut + "')");
           SqlDataReader ejecutar = com.ExecuteReader();
           con.Close();
       } 
       #endregion

       

       

 
    }
}
#endregion